#include<reg52.h>
#include"hgmcu.h"
uint num;
uchar qian,bai,shi,ge,look;
uchar code table[]={
0xC0,0xf9,0xA4,0xB0,
0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,
0xC6,0xA1,0x86,0x8E};
void delay(uint z);
void zh();
void shownum(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time);
void main()
{
	while(1)
	{
		if(k4==0)
		{
			if(look==0)
				{look=1;}
			else
				{look=0;}
			while(!k4)
			{shownum(qian,bai,shi,ge,10,10);}
		}
		if(look==0)
		{
			led1=1;
			if(k1==0)
			{
				if(k3==0)
					{num+=10;}
				else
					{num++;}
				zh();
				while(!k1)
				{
					if(k2==0)
					{
						if(k3==0)
						{num+=990;zh();}
						else
						{num+=99;zh();}
						while(!k2)
							{shownum(qian,bai,shi,ge,10,10);}
					}
					else
						{shownum(qian,bai,shi,ge,10,10);}
				}
			}
			else
			{
				if(k2==0)
				{
					if(k3==0)
						{num-=10;}
					else
						{num--;}
					zh();
					while(!k2)
						{
							if(k1==0)
							{
								if(k3==0)
								{num-=990;zh();}
								else
								{num-=99;zh();}
								while(!k2)
									{shownum(qian,bai,shi,ge,10,10);}
							}
							shownum(qian,bai,shi,ge,10,10);
						}
				}
				else
				{shownum(qian,bai,shi,ge,10,10);}
			}
		}
		else
		{
			led1=0;
			{shownum(qian,bai,shi,ge,10,10);}
		}
	}
}
void delay (uint z)
{
	uint x,y;
	for(x=z;x>0;x--)
		for(y=11;y>0;y--);
}
void shownum(uchar qian,uchar bai,uchar shi,uchar ge,uchar cyc,uchar time)
{
uchar xh;
for(xh=0;xh<cyc;xh++)
		{
			//qbsg
			P0=table[qian];
			P20=0;
			delay(time);
			P20=1;
			P0=table[bai];
			P21=0;
			delay(time);
			P21=1;
			P0=table[shi];
			P22=0;
			delay(time);
			P22=1;
			P0=table[ge];
			P23=0;
			delay(time);
			P23=1;
		}
}
void zh()
{
	qian=num/1000;
	bai=num%1000/100;
	shi=num%100/10;
	ge=num%10;
}